var setupTask;
var reviveCount = 5;
var mapIds = [940400000];
var 准备地图 = 450011220;
var eventName = "痛苦迷宫_中心";

function init() {}

function setup(d, b) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var d = em.newInstance(eventName);
    for (var c = 0; c < mapIds.length; c++) {
        var e = d.setInstanceMap(mapIds[c]);
        e.resetFully();
        e.killAllMonsters(true)
    }
    for (var c = 940401000; c <= 940404900; c += 100) {
        var e = d.setInstanceMap(c);
        e.resetFully();
        e.killAllMonsters(true);
        if (c % 1200 == 100) {
            for (var a = 0; a < 20; a++) {
                e.spawnMonsterOnGroundBelow(em.getMonster(rand(9833299, 9833300)), new java.awt.Point(rand(e.getLeft(), e.getRight()), rand(e.getTop(), e.getBottom() - 200)))
            }
        } else {
            if (c % 1200 == 200) {
                for (var a = 0; a < 20; a++) {
                    e.spawnMonsterOnGroundBelow(em.getMonster(9833291), new java.awt.Point(rand(e.getLeft(), e.getRight()), rand(e.getTop(), e.getBottom() - 200)))
                }
            } else {
                if (c % 1200 == 300) {
                    for (var a = 0; a < 20; a++) {
                        e.spawnMonsterOnGroundBelow(em.getMonster(rand(9833294, 9833295)), new java.awt.Point(rand(e.getLeft(), e.getRight()), rand(e.getTop(), e.getBottom() - 200)))
                    }
                } else {
                    if (c % 1200 == 400) {
                        for (var a = 0; a < 25; a++) {
                            e.spawnMonsterOnGroundBelow(em.getMonster(rand(9833296, 9833298)), new java.awt.Point(rand(e.getLeft(), e.getRight()), rand(e.getTop(), e.getBottom() - 200)))
                        }
                    }
                }
            }
        }
    }
    d.initMaze(1, 6, 6);
    return d
}

function rand(b, a) {
    return Math.floor(Math.random() * (a - b + 1)) + b
}

function onPlayerRegistered(b, a) {
    b.startEventTimer(1000 * 60 * 20);
    a.getAPI().enterMaze()
}

function onMonsterKilled(b, d, c) {
    if (d >= 8644765 && d <= 8644767) {
        player.getAPI().getWeatherEffectNotice("迷宫之核被破坏掉之后，关闭的门打开了。", 253, 15000, 1);
        player.getMap().getReactorByName("exit00").forceHitReactor(player, 2);
        b.setProperty("core", 2)
    } else {
        if (validMobs(player) == 0) {
            player.getMap().getWeatherEffectNotice("迷宫的门打开了。", 253, 15000, 1);
            var a = ["up00", "down00", "left00", "right00", "exit00"];
            a.forEach(function (e) {
                if (player.getMap().getReactorByName(e).getState() == 1) {
                    player.getMap().getReactorByName(e).forceHitReactor(player, 2)
                }
            })
        }
    }
}
var mobs = [9833299, 9833300, 9833291, 9833294, 9833295, 9833296, 9833297, 9833298];

function validMobs(b) {
    var c = 0;
    for (var a = 0; a < mobs.length; a++) {
        c += b.getMap().countMonsterById(mobs[a])
    }
    return c
}

function onMapChanged(c, b, a) {
    if (!c.getMapIds().contains(a)) {
        on玩家退场(c, b, false);
        return
    }
}

function Chuansong(b, a) {
    if (b.getMapInstance(993066800).getCharactersSize() != 0) {
        warp(b, 993066900, 0)
    } else {
        if (b.getMapInstance(993066900).getCharactersSize() != 0) {
            warp(b, 993067000, 0)
        } else {
            if (b.getMapInstance(993067000).getCharactersSize() != 0) {
                warp(b, 993060069, 0)
            }
        }
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function warp(d, c, a) {
    for (var b = 0; b < d.getPlayerCount(); b++) {
        d.getPlayers().get(b).getAPI().warp(c, a)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function onPlayerRevived(b, a) {
    return false
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function playerExit(b, a) {
    em.broadcastServerMsg("[playerExit]");
    on玩家退场(b, a, false)
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onMonsterDamaged(b, a, d, e, c) {}

function onItemPickedUp() {};